package br.com.wuo.karina.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.Border;

import br.com.wuo.karina.model.ProfessorGrid;
import br.com.wuo.karina.model.dao.impl.AulaDaoImpl;

public class PagamentosBottomPane extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private Pagamentos pagamentos;
	
	
	private JButton btnPagar;
	private JButton btnLimpar;
	private JButton btnSair;
	private AulaDaoImpl aulaDao;
	
	public PagamentosBottomPane() {
		initialize();
		addListener();
	}

	private void initialize() {
		
		aulaDao = new AulaDaoImpl();

		Border innerBorder = BorderFactory.createEmptyBorder(5, 5, 5, 5);
		Border outerBorder = BorderFactory.createTitledBorder("Total:");
		
		btnPagar = new JButton("Pagar");
		btnLimpar = new JButton("Limpar");
		btnSair = new JButton("Sair");
		
		setLayout(new GridBagLayout());
		setBorder(BorderFactory.createEtchedBorder());
		
		GridBagConstraints gc = new GridBagConstraints();
		
		gc.weightx = 1;
		gc.weighty = 0;
		
		gc.gridx = 0;
		gc.gridy = 1;
		gc.anchor = GridBagConstraints.FIRST_LINE_END;
		gc.insets = new Insets(0, 255, 15, 0);
		add(btnPagar, gc);
		
		gc.gridx = 1;
		gc.anchor = GridBagConstraints.CENTER;
		gc.insets = new Insets(0, 0, 15, 0);
		add(btnLimpar, gc);
		
		gc.gridx = 2;
		gc.anchor = GridBagConstraints.FIRST_LINE_START;
		gc.insets = new Insets(0, 0, 15, 255);
		add(btnSair, gc);
		
	}
	
	public void addListener() {
		
		btnPagar.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				ArrayList<ProfessorGrid> pagamentos;
				try {
					pagamentos = aulaDao.getAllAulasByProfessorGrid();
					for(ProfessorGrid aula:pagamentos){
						System.out.println("nome: " + aula.getNomeCompleto() + " data: " + aula.getMes()+"/"+ aula.getAno() + " pagamento: " + aula.getPagamento() + " valor: " + aula.getValor() );
					}
				} catch (SQLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				
				
				
			}
		});
		
	}

	public Pagamentos getPagamentos() {
		return pagamentos;
	}


	public void setPagamentos(Pagamentos pagamentos) {
		this.pagamentos = pagamentos;
		
	}
}
